<template>
	<view class="container">
		<star-nav title="关于我们" :type="3" icon="/static/myimages/m14.png"></star-nav>
		<view style="width: 100%;height: 30rpx;"></view>
		<view class="conter">
			<view  class="ver">
				<view>版本号</view>
				<view class="verRight">
					<view>{{versionUpdate.show?versionUpdate.newVersion:versionUpdate.version}}</view>
					<view v-if="versionUpdate.show" class="verBut" @click="handleVer">升级新版本</view>
				</view>
			</view>
		</view>
		<star-version ref="versionRef"></star-version>
	</view>
</template>

<script>
	import {
		getPatchManage
	} from '@/api/login.js'
	export default {
		data() {
			return {
				// app版本更新Data
				versionUpdate: {
					version: '1.0.0', //当前版本
					newVersion: '1.0.0', //更新版本
					versionContent: "", //更新内容
					downloadTask: null, //更新任务
					updateType: null, //0 热更新  1整包更新
					show: false, //更新弹框
					patchUrl: "", //更新wgt包
					patchiosUrl:"",
					schedule: { // 更新进度对象
						// 进度
						progress: "",
						// 已经下载长度
						totalBytesWritten: "",
						// 预期下载长度
						totalBytesExpectedToWrite: ""
					},
					time: 0 //更新进度更新间隔时间ms
				}
			}
		},
		onLoad() {
			this.detectNewVersion()
		},
		methods: {
			// 检测新版本
			detectNewVersion() {
				// #ifdef APP-PLUS  
				plus.runtime.getProperty(plus.runtime.appid, async (widgetInfo) => {
					// 拿到当前app版本
					let version = widgetInfo.version;
					this.versionUpdate.version = version;
					// 获取最新版本api接口 需要返回 version , content , source_download三个属性
					const res = await getPatchManage()
					let data = res.data // 拿到数据
					this.versionUpdate.updateType = data.updateType
					this.versionUpdate.newVersion = data.versionCode // 保存新版本--用来弹框展示
					this.versionUpdate.versionContent = data.content // 保存更新内容--用来弹框展示
					// 有新版本--进行更新
					if (data.versionCode != version) {
					this.versionUpdate.patchiosUrl = res.data.iosDownloadUrl
					this.versionUpdate.patchUrl = res.data.downloadUrl // 保存新版本wgt包
						this.versionUpdate.show = true // 显示更新弹框
						uni.hideTabBar();
					} 
				})
				// #endif
			},
			handleVer(){
				this.$refs.versionRef.detectNewVersion()
			}
		}
	}
</script>

<style scoped>
	.verBut{
		width: 150rpx;
		height: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 19rpx;
		color: #333333;
		border-radius: 15rpx;
		background: linear-gradient(to right, #704BF7, #0CECA6);
		margin-left: 15rpx;
	}
	.verRight{
		height: 80rpx;
		display: flex;
		align-items: center;
	}
	.ver{
		width: 95%;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #FFFFFF;
		border-bottom: 1rpx solid #FFFFFF;
	}
	.conter {
		width: 710rpx;
		max-height: calc(100vh - 230rpx);
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40rpx 0;
		box-sizing: border-box;
		
		margin: 0 auto;
	}

	.container {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
	}

</style>